package com.qianbao.qianbaobusiness.ui.support.businessanalysis;

import com.androidbase.base.mvp.RxMvpPresenter;
import com.androidbase.utils.RxUtils;
import com.baseandroid.config.MyApi;
import com.baseandroid.retrofit.RxObserver;
import com.baseandroid.retrofit.json.Data;
import com.qianbao.qianbaobusiness.json.BusinessAnalysisBean;

import javax.inject.Inject;

/**
 * @author: Routee
 * @date 2018/6/13
 * @mail wangc4@qianbaocard.com
 * ------------1.本类由Routee开发,阅读、修改时请勿随意修改代码排版格式后提交到git。
 * ------------2.阅读本类时，发现不合理请及时指正.
 * ------------3.如需在本类内部进行修改,请先联系Routee,若未经同意修改此类后造成损失本人概不负责。
 */
public class BusinessAnalysisPresenter extends RxMvpPresenter<BusinessAnalysisView> {
    MyApi mApi;

    @Inject
    public BusinessAnalysisPresenter(MyApi api) {
        mApi = api;
    }

    public void getManagerStatics(String merchantNo) {
        mApi.getManagerStatic(merchantNo).compose(RxUtils.applySchedulersLifeCycle(getView()))
                .subscribe(new RxObserver<Data<BusinessAnalysisBean>>() {
                    @Override
                    public void onNext(Data<BusinessAnalysisBean> data) {
                        if (RxObserver.checkJsonCode(data, false)) {
                            getView().getManagerStaticsSuccess(data.getResult());
                        } else {
                            getView().onError();
                        }
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                        getView().onError();
                    }
                });
    }
}
